-----------------------------------------------------------------------------
-- 1.补全
-----------------------------------------------------------------------------

return {

	---------------------------------------
	-- 补全
	-- https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion
	-- https://github.com/hrsh7th/nvim-cmp
	-- https://github.com/onsails/lspkind-nvim
	---------------------------------------
	-- nvim-cmp
	{
		"hrsh7th/nvim-cmp",
		dependencies = {
			"lspkind-nvim",
			"nvimdev/lspsaga.nvim",
		},
		config = function()
			local cmp = require("cmp")
			local lspkind = require("lspkind")
			cmp.setup({
				-- 指定 snippet 引擎
				snippet = {
					expand = function(args)
						-- For `vsnip` users.
						-- vim.fn["vsnip#anonymous"](args.body)

						-- For `luasnip` users.
						require("luasnip").lsp_expand(args.body)

						-- For `ultisnips` users.
						-- vim.fn["UltiSnips#Anon"](args.body)

						-- For `snippy` users.
						-- require'snippy'.expand_snippet(args.body)
					end,
				},

				-- 来源
				sources = cmp.config.sources({
					{ name = "nvim_lsp" },
					{ name = "nvim_lsp_signature_help" },

					{ name = "buffer" },
					-- { name = 'spell' },
					--
					-- For vsnip users.
					-- { name = "vsnip" },

					-- For luasnip users.
					{ name = "luasnip" },

					--For ultisnips users.
					-- { name = 'ultisnips' },

					-- -- For snippy users.
					-- { name = 'snippy' },
				}, {
					{ name = "path" },
				}),
				-- 快捷键
				mapping = require("keybinding").cmp(cmp),
				-- 使用lspkind-nvim显示类型图标
				formatting = {
					format = lspkind.cmp_format({
						mode = "symbol_text",
						--mode = 'symbol', -- show only symbol annotations
						maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
						-- The function below will be called before any actual modifications from lspkind
						-- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
						before = function(entry, vim_item)
							-- Source 显示提示来源
							vim_item.menu = "[" .. string.upper(entry.source.name) .. "]"
							return vim_item
						end,
					}),
				},
			})
			-- Use buffer source for `/`.
			cmp.setup.cmdline("/", {
				sources = {
					{ name = "buffer" },
				},
			})
			-- Use cmdline & path source for ':'.
			cmp.setup.cmdline(":", {
				mapping = cmp.mapping.preset.cmdline(),
				sources = cmp.config.sources({
					{ name = "path" },
				}, {
					{ name = "cmdline" },
				}),
			})
		end,
	},

	-- ## Snippet 引擎

	-- https://github.com/hrsh7th/vim-vsnip
	-- 'hrsh7th/vim-vsnip',

	-- https://github.com/L3MON4D3/LuaSnip
	{
		"L3MON4D3/LuaSnip",
		-- follow latest release.
		version = "2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
		-- install jsregexp (optional!).
		build = "make install_jsregexp",
		config = function()
			require("luasnip.loaders.from_vscode").lazy_load()
		end,
	},

	-- ## 常见编程语言代码段
	-- https://github.com/rafamadriz/friendly-snippets
	"rafamadriz/friendly-snippets",
	-- ## 补全源
	"hrsh7th/cmp-vsnip", -- { name = 'vsnip' }
	"hrsh7th/cmp-nvim-lsp", -- { name = nvim_lsp }
	"hrsh7th/cmp-buffer", -- { name = 'buffer' },
	"hrsh7th/cmp-path", -- { name = 'path' }
	"hrsh7th/cmp-cmdline", -- { name = 'cmdline' }
	"hrsh7th/cmp-nvim-lsp-signature-help", -- { name = 'nvim_lsp_signature_help' }
	-- ## 拼写建议
	"f3fora/cmp-spell",

	---------------------------------------
	-- lspkind
	-- 1.为cmp提供图标
	-- 2.为cmp提供格式化参数
	-- https://github.com/onsails/lspkind-nvim
	---------------------------------------
	{
		"onsails/lspkind-nvim",
		config = function()
			local lspkind = require("lspkind")
			lspkind.init({
				-- default: true
				-- with_text = true,
				-- defines how annotations are shown
				-- default: symbol
				-- options: 'text', 'text_symbol', 'symbol_text', 'symbol'
				mode = "symbol_text",
				-- default symbol map
				-- can be either 'default' (requires nerd-fonts font) or
				-- 'codicons' for codicon preset (requires vscode-codicons font)
				--
				-- default: 'default'
				preset = "codicons",
				-- override preset symbols
				--
				-- default: {}
				symbol_map = {
					Text = "",
					Method = "",
					Function = "",
					Constructor = "",
					Field = "ﰠ",
					Variable = "",
					Class = "ﴯ",
					Interface = "",
					Module = "",
					Property = "ﰠ",
					Unit = "塞",
					Value = "",
					Enum = "",
					Keyword = "",
					Snippet = "",
					Color = "",
					File = "",
					Reference = "",
					Folder = "",
					EnumMember = "",
					Constant = "",
					Struct = "פּ",
					Event = "",
					Operator = "",
					TypeParameter = "",
				},
			})
		end,
	},


    -----------------------------------------------------------------------------
    -- ## 自动关闭标签
    -- https://github.com/windwp/nvim-autopairs
    -----------------------------------------------------------------------------
    {
        "windwp/nvim-autopairs",
        dependencies = {"hrsh7th/nvim-cmp"},
        config = function()
            local  autopairs = require("nvim-autopairs")
            autopairs.setup({
                check_ts = true,
                ts_config = {
                    lua = { "string" }, -- it will not add a pair on that treesitter node
                    javascript = { "template_string" },
                    java = false, -- don't check treesitter on java
                },
            })
            -- If you want insert `(` after select function or method item
            local cmp_autopairs = require("nvim-autopairs.completion.cmp")
            local cmp = require("cmp")
            cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = "" } }))
        end,
    },
}

